using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class BlockedUserDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public BlockedUserDA()
		{
		}

		public BlockedUserDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the BlockedUser table.
		/// </summary>
		public  int Insert(BlockedUser blockedUser)
		{
			ValidationUtility.ValidateArgument("blockedUser", blockedUser);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", blockedUser.TenantID),
				new SqlParameter("@BlockedProfileID", blockedUser.BlockedProfileID)
			};

			blockedUser.ProfileID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "BlockedUserInsert", parameters));
			return blockedUser.ProfileID;
		}

		/// <summary>
		/// Deletes a record from the BlockedUser table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "BlockedUserDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the BlockedUser table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "BlockedUserDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects all records from the BlockedUser table.
		/// </summary>
		public  List<BlockedUser> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "BlockedUserSelectAll", parameters))
			{
				List<BlockedUser> blockedUserList = new List<BlockedUser>();
				while (dataReader.Read())
				{
					BlockedUser blockedUser = MakeBlockedUser(dataReader);
					blockedUserList.Add(blockedUser);
				}

				return blockedUserList;
			}
		}

		/// <summary>
		/// Selects all records from the BlockedUser table by a foreign key.
		/// </summary>
		public  List<BlockedUser> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "BlockedUserSelectAllByProfileID", parameters))
			{
				List<BlockedUser> blockedUserList = new List<BlockedUser>();
				while (dataReader.Read())
				{
					BlockedUser blockedUser = MakeBlockedUser(dataReader);
					blockedUserList.Add(blockedUser);
				}

				return blockedUserList;
			}
		}

		/// <summary>
		/// Selects all records from the BlockedUser table by a foreign key.
		/// </summary>
		public  List<BlockedUser> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "BlockedUserSelectAllByTenantID", parameters))
			{
				List<BlockedUser> blockedUserList = new List<BlockedUser>();
				while (dataReader.Read())
				{
					BlockedUser blockedUser = MakeBlockedUser(dataReader);
					blockedUserList.Add(blockedUser);
				}

				return blockedUserList;
			}
		}

		/// <summary>
		/// Creates a new instance of the BlockedUser class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  BlockedUser MakeBlockedUser(SqlDataReader dataReader)
		{
			BlockedUser blockedUser = new BlockedUser();
			blockedUser.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			blockedUser.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			blockedUser.BlockedProfileID = SqlClientUtility.GetInt32(dataReader, "BlockedProfileID", 0);

			return blockedUser;
		}

		#endregion
	}
}
